package com.cjq.config;

import com.cjq.constant.Constant;
import com.cjq.core.route.RouteDefinition;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
@Data
@ConfigurationProperties(prefix = "tcp")
public class GatewayConfig {
    @Value("${tcp.port}")
    Integer port;
    @Value("${tcp.boss}")
    Integer boss;
    @Value("${tcp.work}")
    Integer work;

    @Value("${tcp.filterList}")
    String filterList;
    private List<RouteDefinition> routeList=new ArrayList<>();
    @Bean
    public EventLoopGroup bossGroup() {
        return new NioEventLoopGroup(StringUtils.isEmpty(boss) ? Constant.BOSS_GROUP_SIZE : boss);
    }

    @Bean
    public EventLoopGroup workerGroup() {
        return new NioEventLoopGroup(StringUtils.isEmpty(work) ? Constant.WORKER_GROUP_SIZE : work);
    }

}
